//获取ul
let uu = document.querySelector('#product ul')
//1.发起请求获取列表数据

//2.根据列表数据展示列表内容

//3.需要将商品的productId绑定到元素上

//4.点击元素进行跳转,跳到detail页面 并且要携带productId
let el = "";
fetch('http://chst.vip:1234/api/getmoneyctrl')
    .then(body => body.json())
    .then(res => {
        console.log(res)
        res.result.forEach(item => {
            let regExp = /(?<=imgurl=)[^'"]*/;
            // console.log(item)
            //处理图片
            let r = item.productImg2.match(regExp);
            // console.log(r)
            el += `<li>
            <a href="./pages/indexDetail.html?productid=${item.productId}" class="clearfix">
                <div class="img fl">
                    <img src=${r[0]} height="100" alt="">
                </div>
                <div class="infoR">
                    <div class="title">
                        <h4>${item.productName}
                            <span>${item.productPinkage}</span>
                        </h4>
                    </div>
                    <div class="other">
                        <span class="mall fl">${item.productFrom}     |${item.productTime}</span>
                        <em class="fr">
                            <span> ${item.productComCount}</span>
                        </em>
                    </div>
                </div>
            </a>
        </li>`
        })
        uu.innerHTML = el;
    })
//事件委托注册事件

uu.onclick = function (e) {
    if (e.target.localName === 'li') {
        let _this = e.target;
        console.log(_this)

        //获取当前li标签的productid

        let id = _this.getAttribute('productid')

        location.href = "./pages/indexDetail.html?productid=" + id
    }
}